package com.lalala.UI;

import java.util.Scanner;
import com.lalala.Service.ManageService;
import com.lalala.util.MyUIUtils;

/**
 * 表现层<p>用户交互界面
 *
 * @author lalala
 * @createdate 2021/9/1 19:34 周三
 */
public class ManageUI {
	Scanner input = new Scanner(System.in);
	ManageService manageService = new ManageService();

	/**
	 * 添加学生
	 */
	public void add() {
		System.out.print("请输入学号:");
		String stuID = input.nextLine();
		System.out.print("请输入姓名:");
		String name = input.nextLine();
		System.out.print("['male' or 'female']请输入性别:");
		String gender  = input.nextLine();
		System.out.print("[yyyy-MM-dd]请输入生日:");
		String birthday = input.nextLine();
		System.out.print("请输入电话号码:");
		String phoneNumber = input.nextLine();
		boolean bool = manageService.add(stuID, name, gender, birthday, phoneNumber);
		if (bool)
			System.out.println("添加成功！");
		else
			System.out.println("添加失败！");
	}

	/**
	 * 修改学生信息
	 */
	public void alter() {
		System.out.print("请输入学号:");
		String stuID = input.nextLine();
		boolean b = manageService.queryByID(stuID);
		if (!b) {
			System.out.println("无此学生!");
			return;
		}
		MyUIUtils.printOption("姓名","性别","生日","电话号码");
		String op = input.nextLine();
		if (op.equals("0")){
			return;
		} else if (op.matches("[1-4]")){
			System.out.print("请输入新信息:");
			boolean alter = manageService.alter(stuID, op, input.nextLine());
			if (alter)
				System.out.println("修改成功!");
			else
				System.out.println("修改失败!");
		} else
			System.out.println("输入有误!");
	}

	/**
	 * 删除学生信息
	 */
	public void delByID() {
		System.out.print("请输入学号:");
		String stuID = input.nextLine();
		boolean del = manageService.delByID(stuID);
		if (del) System.out.println("删除成功!");
		else System.out.println("删除失败!");
	}

	/**
	 * 查询学生信息(ID)
	 */
	public void queryByID() {
		System.out.print("请输入学号:");
		String stuID = input.nextLine();
		boolean b = manageService.queryByID(stuID);
		if (!b) System.out.println("未查询到信息！");
	}

	/**
	 * 查询全部学生信息
	 */
	public void queryAll() {
		int i = manageService.queryAll();
		System.out.printf("查询到[%d]条结果!\n",i);
	}
}
